package edu.ccut.saturn.manager.menu.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IMuneItemInfo;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnMenuManager;

public class MenuListToMap extends DefaultComponent {
	@SuppressWarnings("unchecked")
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {

		List<IMuneItemInfo> menuItemList = (List<IMuneItemInfo>)parameterContext.getParameterValue(0);
		
		List<Map<String, String>> result = new ArrayList<Map<String,String>>();
		
		if(menuItemList != null){
			for(IMuneItemInfo menuItemInfo : menuItemList){
				
				Map<String, String> map = new HashMap<String, String>();
				
				map.put("id", menuItemInfo.getId());
				map.put("parentId",menuItemInfo.getParentId());
				map.put("label", menuItemInfo.getLabel());
				map.put("path", menuItemInfo.getPath());
                map.put("symbolicName", menuItemInfo.getMenuInfo().getBundleSymbolicName());	
              
				String varid = menuItemInfo.getId();
				int childSize = SaturnMenuManager.getInstance().getMenuItemsOfRootMenuItem(varid).size();
				
				map.put("childSize", String.valueOf(childSize));
			
				result.add(map);
			}
		}
		
		parameterContext.setParameter(0, result);
	}
}